"""
Descripttion: 
Author: jdz
version: 
Date: 2024-08-12 14:21:56
LastEditors: jdz
LastEditTime: 2024-08-12 14:23:31
"""

from sqlalchemy import Column, Float, Integer, String, create_engine
from sqlalchemy.orm import DeclarativeBase, mapped_column, sessionmaker, Mapped

mysql_engine = create_engine(
    "mysql+pymysql://root:sql123@113.44.65.140:3306/flex-study", echo=True
)


class Base(DeclarativeBase):
    pass


class Book(Base):
    __tablename__ = "Book"

    id: Mapped[int] = mapped_column("book_id", primary_key=True)
    book_name: Mapped[str] = mapped_column(String(50), nullable=False)
    price: Mapped[float] = mapped_column(Float, nullable=False)

    def __repr__(self):
        return f"<Book(id={self.id}, book_name={self.book_name}, price={self.price})>"

    ""


Base.metadata.create_all(mysql_engine)
Session = sessionmaker(bind=mysql_engine)
